const mysql = require("mysql"); //cnpm install mysql --save

// 连接mysql
const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'dscadmin'
});

function request(sql) {
    return new Promise((resolve, reject) => {
        connection.query(sql, (err, data) => {
            if (err) {
                reject(err);

            } else {
                resolve(data);
            }
        })
    })
}

// 暴露
module.exports = {
    connection,
    request
}